<template>
  <a-form-model
    :ref="'anamnesis' + confirmType"
    :model="anamnesis"
    :label-col="formItemLayout.labelCol"
    :wrapper-col="formItemLayout.wrapperCol"
    labelAlign="left"
  >
    <a-form-model-item label="确诊情况">
      <a-radio-group v-model="anamnesis.kidney">
        <a-radio :value="1"> 确诊有 </a-radio>
        <a-radio :value="2"> 确诊无 </a-radio>
        <a-radio :value="3"> 未确诊 </a-radio>
      </a-radio-group>
    </a-form-model-item>
    <a-divider />
    <div class="content" v-show="anamnesis.kidney === 1">
      <a-form-model-item label="确诊日期">
        <a-date-picker
          :disabled-date="disabledDate"
          v-model="anamnesis.kidneyDiseaseDate"
          @change="onChange"
          :style="{ width: '200px' }"
        />
      </a-form-model-item>

      <a-form-model-item label="所患疾病">
        <j-multi-select-tag v-model="anamnesis.kidneyDisease" dictCode="pubDossierKidney" type="checkbox">
        </j-multi-select-tag>

        <a-input
          v-show="anamnesis.kidneyDisease != null && anamnesis.kidneyDisease.indexOf('4') > -1"
          v-model="anamnesis.kidneyDiseaseOther"
        />
      </a-form-model-item>

      <a-form-model-item label="尿常规(尿蛋白)">
        <a-radio-group v-model="anamnesis.kidneyPro">
          <a-radio :value="1"> 阴性 </a-radio>
          <a-radio :value="2"> 阳性 </a-radio>
        </a-radio-group>
      </a-form-model-item>

      <a-form-model-item label="尿白蛋白/尿肌酐(ACR)">
        <a-input v-model="anamnesis.kidneyAcr" :style="{ width: '200px' }" />
        mg/g
      </a-form-model-item>

      <a-form-model-item label="血清肌酐(Cr)">
        <a-input-number v-model="anamnesis.kidneyCr" :style="{ width: '200px' }" />
        ummol/L
      </a-form-model-item>

      <a-form-model-item label="肾小球滤过率(GFR)">
        <a-input-number v-model="anamnesis.kidneyGfr" :style="{ width: '200px' }" />
      </a-form-model-item>

      <a-form-model-item label="内生肌酐清除率">
        <a-input-number v-model="anamnesis.kidneyCcr" :style="{ width: '200px' }" />
      </a-form-model-item>

      <a-form-model-item label="其他检查及结果">
        <a-input
          :maxLength="240"
          v-model="anamnesis.kidneyDiseaseChecksOther"
          :style="{ width: '400px' }"
          type="textarea"
          placeholder="限制字数为240"
          :auto-size="{ minRows: 2, maxRows: 6 }"
        />
        <div
          v-if="anamnesis.kidneyDiseaseChecksOther != null && anamnesis.kidneyDiseaseChecksOther.length > 0"
          :style="{ display: 'inline-block', marginLeft: '1rem' }"
        >
          {{ anamnesis.kidneyDiseaseChecksOther.length }}/240
        </div>
      </a-form-model-item>
    </div>
    <a-form-model-item :wrapper-col="{ span: 12, offset: 10 }">
      <a-button type="primary" @click="save" :loading="saveLoading">保存</a-button>
      <a-popconfirm placement="topLeft" ok-text="是" cancel-text="否" @confirm="confirm">
        <template slot="title">
          <p>此操作代表你已完成了页面的填写，是否继续？</p>
        </template>
        <a-button type="primary" style="margin-left: 30px" :loading="saveLoading">确认完成</a-button>
      </a-popconfirm>
    </a-form-model-item>
  </a-form-model>
</template>

<script>
import moment from 'moment'

export default {
  name: 'KidneyDisease',
  props: ['anamnesis'],
  data() {
    return {
      confirmType: 5,
      formItemLayout: {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 4 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        }
      },
      saveLoading: false
    }
  },
  methods: {
    onChange(date, dateString) {
      console.log(date, dateString)
      this.anamnesis.kidneyDiseaseDate = this.anamnesis.kidneyDiseaseDate.format('YYYY-MM-DD hh:mm:ss')
      console.log(this.anamnesis.kidneyDiseaseDate)
    },
    disabledDate(current) {
      // Can not select days before today and today
      return current > moment().endOf('day')
    },
    save() {
      this.saveLoading = true
      this.$emit('save', this.confirmType)
    },
    confirm() {
      this.saveLoading = true
      this.$emit('confirm', this.confirmType)
    }
  }
}
</script>

<style lang="less" scoped></style>

